// Copyright 2009 StarCite Inc.  All rights reserved.
// SyncFilesServlet.java 9:37:32 AM danny.liu
package com.billowsoft.syncer.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.billowsoft.syncer.util.FileUtil;

/**
 * @author danny.liu Nov 29, 2011
 * @version 1.0
 * 
 */
public class SyncFilesServlet extends HttpServlet {

	private static final long serialVersionUID = -926681510763195154L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String filesToSync = req.getParameter("filesToSync");
		String fileBaseDir = req.getParameter("baseDirToSync");
		if(StringUtils.isNotEmpty(filesToSync)){
			String[] fileNames = filesToSync.split(";");
			for(String fileName : fileNames){
				FileUtil.copy(fileBaseDir, fileName, ListLocalFilesServlet.serverDir);
			}
		}

		resp.sendRedirect("./index.jsp");
	}
	
}
